feat(page-cluster): add complete-linkage structural clustering within a block#906
Merged
YusukeHirao merged 2 commits intoJul 4, 2026
Merged
Conversation
… a block Add resolveStructuralClusterKeys, which clusters pages already grouped into one blocking key (e.g. from resolveBlockingGroupKeys) by structural similarity, using complete-linkage hierarchical clustering computed via the NN-chain algorithm for O(n^2) time. Single-linkage (connected components of a similarity-threshold graph) was considered first but rejected: its "chaining" failure mode lets one unrepresentative page transitively merge two otherwise-unrelated templates, which defeats template detection. Complete-linkage requires every pair across two clusters to clear the threshold, ruling that out, at no extra asymptotic cost since the pairwise similarity matrix is computed either way. Add "medoid" and "Murtagh" to the cspell dictionary for the new file's JSDoc.
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
resolveStructuralClusterKeys, which clusters pages already grouped into oneblocking key (e.g. from
resolveBlockingGroupKeys) by structural similarity, usingcomplete-linkage hierarchical clustering computed via the NN-chain algorithm (O(n²)).
first but rejected: its "chaining" failure mode lets one unrepresentative page
transitively merge two otherwise-unrelated templates, defeating template detection.
Complete-linkage requires every pair across two clusters to clear the threshold,
ruling that out, at no extra asymptotic cost since the pairwise similarity matrix is
computed either way.
the exact clustering in O(n²), and real-data validation (see test plan) confirmed
O(n²) is fast enough at the largest real block size found (~1,400 pages, ~685ms).
Test plan
yarn build/yarn lint/yarn testpass/code-review xhighrun; 4 findings (floating-point threshold boundary epsilon,unicorn/prefer-math-trunc, Prettier formatting, cspell) all fixed/qa-engineerreview added a differential test against a naive brute-forcecomplete-linkage reference (caught one real algorithm bug during development —
an early-exit-on-threshold that's unsound when multiple disjoint NN-chains
exist), plus a regression test for the epsilon fix and threshold boundary tests
/product-managerand/docreviews passed with one JSDoc gap fixedperformance at the largest observed real block size, and found (as a documented,
non-blocking finding for a future iteration) that per-page body classes on some
real sites can zero out structural similarity between same-template pages —
a caller-side normalization concern, not a bug in this function